<?php
	include_once('dbcon.php');
	include_once('constants.php');
	include_once('update_user_points_db.php');

	$categories_query = $mysqli->query("SELECT category_id, creation_date FROM categories");
 	
    while ($category = $categories_query->fetch_assoc()) {
		$contents_query = $mysqli->query("SELECT sum(likes) as sumLikes, sum(dislikes) as sumDislikes FROM contents WHERE category_id='".$category['category_id']."' && points>='".MIN_POINTS_TO_BESTS."'");
		$content = $contents_query->fetch_assoc();

		$mysqli->query("UPDATE categories SET likes='".$content['sumLikes']."', dislikes='".$content['sumDislikes']."', score='".getCategoryScore($content['sumLikes'], $content['sumDislikes'], $category['creation_date'])."' WHERE category_id='".$category['category_id']."'");
		echo $mysqli->error."</br>";
    }

?>